-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Further fix to configuration classes using ISet, resolving regression with custom 404 pages #19573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
… with custom 404 pages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes the binding regression for custom 404 pages by changing the configuration property type and updating affected tests, and suppresses a compatibility warning.
- Changed
Error404Collection
fromISet<ContentErrorPage>
toIEnumerable<ContentErrorPage>
with a C# 12 collection expression default. - Updated unit test initializer syntax in
ContentSettingsValidatorTests.cs
to use[...]
. - Added a compatibility suppression for the breaking change in
CompatibilitySuppressions.xml
.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/Validation/ContentSettingsValidatorTests.cs | Switched collection initializer syntax to C# 12 [...] |
src/Umbraco.Core/Configuration/Models/ContentSettings.cs | Changed property type from ISet to IEnumerable |
src/Umbraco.Core/CompatibilitySuppressions.xml | Added suppression for CP0002 on Error404Collection |
Comments suppressed due to low confidence (2)
src/Umbraco.Core/Configuration/Models/ContentSettings.cs:53
- Changing Error404Collection from ISet to IEnumerable removes set semantics and mutability; consider using IReadOnlySet or IReadOnlyCollection to preserve uniqueness and clearly express intended behavior.
public IEnumerable<ContentErrorPage> Error404Collection { get; set; } = [];
src/Umbraco.Core/Configuration/Models/ContentSettings.cs:50
- [nitpick] The XML doc still implies set behavior; update the summary to reflect the change to an IEnumerable and clarify whether duplicates are permitted.
/// Gets or sets a value for the collection of error pages.
Will this also apply to version 15? I have the same problem in 15.4.1 |
No, this is specifically fixing a regression issue in 16, so if you are having issues with 15 it'll likely be unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
Please note that this is a breaking change due to the change of public signature. It is, however, a strictly necessary change which fixes a regression, and thus I'm accepting it for 16.1 👍
I also went the code route to test this 🤓
Given this code:
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Configuration.Models;
namespace Umbraco.Cms.Web.UI.Custom;
public class TestError404CollectionComponent : IComponent
{
private readonly ContentSettings _contentSettings;
private readonly ILogger<TestError404CollectionComponent> _logger;
public TestError404CollectionComponent(
IOptions<ContentSettings> contentSettings,
ILogger<TestError404CollectionComponent> logger)
{
_logger = logger;
_contentSettings = contentSettings.Value;
}
public void Initialize()
=> _logger.LogInformation(
"### Found {numberOf404Configs} 404 page configs ###",
// the fix is breaking, so this line needs updating after applying the fix
_contentSettings.Error404Collection.Count);
public void Terminate()
{
}
}
public class TestError404CollectionComposer : ComponentComposer<TestError404CollectionComponent>
{
}
...and this 404 configuration:
"Error404Collection": [
{
"Culture": "en-us",
"ContentKey": "575b9a71-28d2-47b0-bd94-ab98e0fc5f2d"
},
{
"Culture": "da-dk",
"ContentKey": "d35282e3-3a2d-4566-965a-c2d91b0fe46e"
}
]
Without the fix I get: ### Found 0 404 page configs ###
❌
With the fix I get the expected: ### Found 2 404 page configs ###
✅
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: https://forum.umbraco.com/t/issue-with-404-page-configuration/4471/5 |
Prerequisites
Resolves: #19567
Description
The cause of this issue was another cases of issues involved in the fix #19229, where
ISet
in configuration classes aren't bound.Note that I've added a compatibility suppression for the breaking change, which I don't see how we can otherwise avoid.
Testing
Prepare a custom 404 page as per the instructions in the documentation (though note that I found this didn't work when using the name "404" for the document type and template, and instead used "File Not Found"). With this PR in place, the custom 404 should be displayed as expected.
To check via debugging, put a breaking point at the start of
NotFoundHandlerHelper.GetCurrentNotFoundPageId
and verify theerror404Collection
parameter matches the configured value.Release
Can consider for a 16.0.1, otherwise 16.1.0.